package cn.itcast.mapreduce_sort;

import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Counter;
import org.apache.hadoop.mapreduce.Mapper;

import java.io.IOException;

public class SortMapper extends Mapper<LongWritable, Text, PairWritable, Text> {
    @Override
    protected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {

        Counter counter = context.getCounter("MY_MAPAPPER", "MAPPERCOUNT");
        counter.increment(1l);
        String[] strings = value.toString().split("\t");
        PairWritable pairWritable = new PairWritable();
        pairWritable.setFirst(strings[0]);
        pairWritable.setSecond(Integer.parseInt(strings[1]));
        context.write(pairWritable, value);
    }
}
